# -*- coding:utf-8 -*-
"""
Created on 2009-12-25

@author: madlee
"""

ELEMENT_DATA = """symbol, valence_radius, ion_potential, electron_affliation, weight, hydrogen_state, color
'X',0,0,0,0,0, (255, 255, 255)
'H',0.32,13.5984,0.7542,1.00794,1, (255, 255, 255)
'He',0.93,24.5874,0,4.0026,0,  (217, 255, 255)
'Li',1.23,5.3917,0.618,6.941,1, (204, 127, 255)
'Be',0.9,9.3226,0,9.01218,2, (194, 255, 0)
'B',0.82,8.298,0.277,10.811,3, (255, 181, 181)
'C',0.77,11.2603,1.2619,12.011,4, (143, 143, 143)
'N',0.75,14.5341,0,14.0067,3, (46, 79, 248)
'O',0.73,13.6181,1.4611,15.9994,2, (255, 12, 12)
'F',0.72,17.4228,3.4012,18.9984,1, (143, 222, 79)
'Ne',0.71,21.5645,0,20.1797,0, (179, 227, 245)
'Na',1.54,5.1391,0.5479,22.98977,1, (171, 92, 243)
'Mg',1.36,7.6462,0,24.305,2, (138, 255, 0)
'Al',1.18,5.9858,0.441,26.98154,3, (191, 166, 166)
'Si',1.11,8.1517,1.385,28.0855,4, (240, 199, 158)
'P',1.06,10.4867,0.7465,30.97376,3, (255, 127, 0)
'S',1.22,10.36,2.0771,32.066,2, (255, 255, 48)
'Cl',0.99,12.9676,3.6127,35.4527,1, (30, 240, 30)
'Ar',0.98,15.7596,0,39.948,0, (127, 209, 227)
'K',2.03,4.3407,0.5015,39.0983,1, (143, 63, 212)
'Ca',1.74,6.1132,0.0184,40.078,2, (61, 255, 0)
'Sc',1.44,6.5614,0.188,44.9559,0, (230, 230, 230)
'Ti',1.32,6.8282,0.079,47.88,0, (191, 194, 199)
'V',1.22,6.7463,0.525,50.9415,0, (166, 166, 171)
'Cr',1.18,6.7666,0.666,51.996,0, (138, 153, 199)
'Mn',1.17,7.434,0,54.938,0, (108, 80, 144)
'Fe',1.17,7.9024,0.151,55.847,0, (222, 102, 51)
'Co',1.16,7.881,0.662,58.9332,0, (240, 143, 158)
'Ni',1.15,7.6398,1.156,58.6934,0, (79, 207, 79)
'Cu',1.17,7.7264,1.235,63.546,0, (199, 127, 51)
'Zn',1.25,9.3941,0,65.39,0, (125, 127, 176)
'Ga',1.26,5.9993,0.3,69.723,3, (194, 143, 143)
'Ge',1.22,7.9,1.233,72.61,4, (102, 143, 143)
'As',1.2,9.8152,0.81,74.9216,3, (189, 127, 227)
'Se',1.16,9.7524,2.0207,78.96,2, (255, 161, 0)
'Br',1.14,11.8138,3.3636,79.904,1, (166, 40, 40)
'Kr',1.89,13.9996,0,83.8,0, (92, 184, 209)
'Rb',2.16,4.1771,0.4859,85.4678,1, (112, 46, 176)
'Sr',1.91,5.6948,0.11,87.62,2, (0, 255, 0)
'Y',1.62,6.217,0.307,88.9059,0, (148, 255, 255)
'Zr',1.45,6.6339,0.426,91.224,0, (148, 225, 225)
'Nb',1.34,6.7589,0.893,92.9064,0, (115, 194, 202)
'Mo',1.3,7.0924,0.746,95.94,0, (84, 181, 181)
'Tc',1.27,7.28,0.55,98,0, (58, 158, 158)
'Ru',1.25,7.3605,1.05,101.07,0, (35, 143, 143)
'Rh',1.25,7.4589,1.137,102.9055,0, (10, 125, 140)
'Pd',1.28,8.3369,0.557,106.42,0, (0, 104, 133)
'Ag',1.34,7.5762,1.302,107.868,0, (191, 191, 191)
'Cd',1.41,8.9937,0,112.41,0, (255, 217, 143)
'In',1.44,5.7864,0.3,114.82,3, (166, 117, 115)
'Sn',1.41,7.3438,0.112,118.71,4, (102, 127, 127)
'Sb',1.4,8.64,1.07,121.757,3, (158, 99, 181)
'Te',1.36,9.0096,1.9708,127.6,2, (212,122,0)
'I',1.33,10.4513,3.059,126.9045,1, (148, 0, 148)
'Xe',1.31,12.1299,0,131.29,0, (66, 158, 176)
'Cs',2.35,3.8939,0.4716,132.9054,1, (87,23,143)
'Ba',1.98,5.2117,0.15,137.33,2, (0, 202, 0)
'La',1.25,5.577,0.5,138.9055,0, (112,212,255)
'Ce',1.65,5.5387,0,140.12,0, (255,255,199)
'Pr',1.65,5.464,0,140.9077,0, (217, 255, 199)
'Nd',1.64,5.525,0,144.24,0, (199, 255, 199)
'Pm',1.63,5.55,0,145,0, (163, 255, 199)
'Sm',1.62,5.6437,0,150.36,0, (143, 255, 199)
'Eu',1.85,5.6704,0,151.965,0, (97, 255, 199)
'Gd',1.61,6.15,0,157.25,0, (69, 255, 199)
'Tb',1.59,5.8639,0,158.9253,0, (48, 255, 199)
'Dy',1.59,5.9389,0,162.5,0, (30, 255, 199)
'Ho',1.58,6.0216,0,164.9303,0, (0, 255, 156)
'Er',1.57,6.1078,0,167.26,0, (0, 230, 117)
'Tm',1.56,6.1843,0,168.9342,0, (0, 212, 81)
'Yb',1.7,6.2542,0,173.04,0, (0, 191, 56)
'Lu',1.56,5.4259,0,174.967,0, (0, 171, 35)
'Hf',1.44,6.8251,0,178.49,0, (76, 194, 255)
'Ta',1.34,7.89,0.322,180.9479,0, (76, 166, 255)
'W',1.3,7.98,0.815,183.85,0, (33, 148, 215)
'Re',1.28,7.88,0.15,186.207,0, (38, 125, 171)
'Os',1.26,8.7,1.1,190.2,0, (38, 102, 151)
'Ir',1.27,9.1,1.565,192.22,0, (23, 84, 135)
'Pt',1.3,9,2.128,195.08,0, (207, 207, 222)
'Au',1.34,9.2257,2.3086,196.9665,0, (255, 207, 33)
'Hg',1.49,10.4375,0,200.59,0, (184, 184, 207)
'Tl',1.48,6.1083,0.2,204.282,3, (166, 84, 76)
'Pb',1.47,7.4167,0.364,207.2,4, (87, 89, 97)
'Bi',1.46,7.289,0.946,208.9804,3, (158, 79, 181)
'Po',1.53,8.4167,1.9,209,2, (171, 92, 0)
'At',1.47,10,2.8,210,1, (117, 79, 69)
'Rn',1.5,10.7485,0,222,0, (66, 130, 151)
'Fr',2.4,3.5,0.46,223,1, (66, 0, 102)
'Ra',2,5.2789,0,226.0254,2, (0, 125, 0)
'Ac',1.5,5.17,0,227,0, (112, 171, 250)
'Th',1.65,6.08,0,232.0381,0, (0, 186, 255)
'Pa',1.65,5.89,0,231.0359,0, (0, 161, 255)
'U',1.42,6.1941,0,238.029,0, (0, 143, 255)
'Np',1.4,6.2657,0,237.0482,0, (0, 127, 255)
'Pu',1.08,6.06,0,244,0, (0, 107, 255)
'Am',1.5,5.993,0,243,0, (84, 92, 243)
'Cm',1.5,6.02,0,247,0, (0, 0, 0)
'Bk',1.5,6.23,0,247,0, (138, 79, 227)
'Cf',1.5,6.3,0,251,0, (161, 53, 212)
'Es',1.5,6.42,0,252,0, (179, 30, 212)
'Fm',1.5,6.5,0,257,0, (179, 30, 186)
'Md',1.5,6.58,0,258,0, (179, 12, 166)
'No',1.5,6.65,0,259,0, (189, 12, 135)
'Lr',1.5,6.6,0,260,0, (199, 0, 102)
"""

from kuai.strtool import create_array
class Element:
    __sym2element = {}
    __elements = []
    
    @staticmethod
    def get(key):
        try: 
            return Element.__elements[key]
        except TypeError:
            try:
                return Element.__sym2element[key]
            except KeyError:
                return Element.__elements[0]
        
    @staticmethod
    def setup(file):
        Element.__elements = create_array(file, Element)
        for i in range(len(Element.__elements)):
            elementI = Element.__elements[i]
            elementI.number = i
            Element.__sym2element[elementI.symbol] = elementI

from cStringIO import StringIO
file = StringIO(ELEMENT_DATA)
Element.setup(file)
del file

